package solutions.leetcode.normal;

import solutions.lib.BaseSolution;

/**
 * @author lizhidong
 * <a href="https://leetcode-cn.com/problems/grumpy-bookstore-owner/">1052. 爱生气的书店老板</a>
 */
public class Solution1052 extends BaseSolution {

    public int maxSatisfied(int[] customers, int[] grumpy, int minutes) {
        int maxCount = 0;
        for (int i = 0; i < customers.length; i++) {
            maxCount += i < minutes || grumpy[i] == 0 ? customers[i] : 0;
        }
        int now = maxCount;
        for (int i = minutes; i < grumpy.length; i++) {
            now = now
                    + (grumpy[i] == 1 ? customers[i] : 0)
                    - (grumpy[i - minutes] == 1? customers[i - minutes] : 0);
            maxCount = Math.max(now, maxCount);
        }
        return maxCount;
    }

    public static void main(String[] args) {
        Solution1052 solution = new Solution1052();
    }
}